// 	ID : pallab81
// 	PROG : 437
// 	LANG : C++
// 	2011-08-24-19.54.35 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define mmk( x, y, z ) mk( x, mk( y,z ) )

inline void wait( double seconds ) {
    double endtime = clock() + ( seconds*CLOCKS_PER_SEC );
    while( clock() < endtime ) {
        ;
    }
}
struct NODE {
    int x,y,z;
    NODE(int x_, int y_, int z_):
        x(x_),y(y_),z(z_) {
        ;
    }
};
int cases;
int N;
vector< NODE > p;
map< pair<int,pair<int,int> >, int > mp;
inline void Read() {
    int xx,yy,zz;
    int i;
    p.clear();
    for(i=0; i<N; ++i) {
        scanf("%d %d %d",&xx,&yy,&zz);
        p.pb( NODE(xx,yy,zz) );
    }
}
int go(NODE A, int flag) {
    int k;
    if( mp.count( mmk(A.x,A.y,A.z) ) ) {
        return mp[ mmk(A.x, A.y, A.z) ];
    }
    int best=0;
    if(flag) {

        for(k=0; k<N; ++k) {
            int pr[3]= {0,1,2};
            int vt[3]= {p[k].x,p[k].y,p[k].z};
            do {
                NODE temp = NODE( vt[pr[0]],vt[pr[1]],vt[pr[2]] );
                best = max( best, temp.z+go(temp,0) );
            } while(next_permutation(pr,pr+3) );
        }
    } else {

        for(k=0; k<N; ++k) {
            int pr[3]= {0,1,2};
            int vt[3]= {p[k].x,p[k].y,p[k].z};
            do {
                if( vt[ pr[0] ] < A.x && vt[ pr[1] ] < A.y ) {
                    NODE temp = NODE( vt[pr[0]], vt[pr[1]], vt[pr[2]] );
                    best = max( best, temp.z+go(temp,0) );
                }
            } while( next_permutation(pr,pr+3));
        }
    }
    mp[ mmk(A.x,A.y,A.z) ]=best;
    return best;
}

inline void Proc() {
    mp.clear();
    int var = go(NODE(0,0,0),1);
    printf("Case %d: maximum height = %d\n",cases,var);
}
int main() {
//#ifndef ONLINE_JUDGE
//    freopen("in.txt","rt",stdin);
//#endif
    cases=1;
    while( scanf("%d",&N)==1 ) {
        if(N==0)break;
        Read();
        Proc();
        ++cases;
    }

    return 0;
}
